package com.hexu.event.service;

import com.hexu.event.dao.LoginDao;

public class LoginInService {
    //创建Dao层对象
    private LoginDao loginDao = new LoginDao();
    private String password1 = null;//用户
    private String password2 = null;//管理员

    //判断密码是否匹配
    public Boolean login(String phoneNumber, String password){
        password1 = loginDao.findPasswordFromUser(phoneNumber);
        password2 = loginDao.findPasswordFromAdministrator(phoneNumber);

        if(password1 != null && password1.equals(password)){
            return true;
        }else if(password2 != null && password2.equals(password)){
            return  true;
        }

        return false;
    }

    //判断登录的是谁
    public int flagChoose(){
        if(password1 != null)
            return 1;
        if(password2 != null)
            return 2;
        return  0;
    }

    //保存管理员密码
    public boolean remember(String phoneNumber){
        return loginDao.remember(phoneNumber);
    }

    //不保存管理员密码
    public boolean notRemember(String phoneNumber){
        return loginDao.notRemember(phoneNumber);
    }

    //保存用户密码
    public boolean remember2(String phoneNumber){
        return loginDao.remember2(phoneNumber);
    }

    //不保存用户密码
    public boolean notRemember2(String phoneNumber){
        return loginDao.notRemember2(phoneNumber);
    }

    //返回账号对应的密码
    public String findPassword(String phoneNumber){
        password1 = loginDao.findPasswordFromUser(phoneNumber);
        password2 = loginDao.findPasswordFromAdministrator(phoneNumber);

        if(password1 != null ){
            return password1;
        }else if(password2 != null ){
            return  password2;
        }

       return null;
    }

    //判断某使用者是否保存密码
    public Boolean ifRemember(String phoneNumber){
        return loginDao.ifRemember(phoneNumber);
    }
}
